﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;

namespace 纯代码创建wpf应用程序 {
    internal class Window1:Window {
        private Button button1 { get; set; }

        public Window1() {
            InitializeComponent();
        }

        private void InitializeComponent() {
            //配置窗体
            this.Width = 285;
            this.Height = 250;
            this.Left = this.Top = 100;
            this.Title = "Code-Only Window";

            //创建停靠面板对象
            DockPanel panel = new DockPanel();

            //创建按钮对象
            button1 = new Button();
            button1.Content = "代码创建的按钮";
            button1.Margin = new Thickness(30);

            button1.Click += button1_click;

            IAddChild container = panel;
            container.AddChild(button1);

            container = this;
            container.AddChild(panel);
        }

        private void button1_click(object sender, RoutedEventArgs e) {
            button1.Content = "点击了";
        }
    }
}
